import os

import yaml


def read_config(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        config = yaml.safe_load(f)
    return config


def new_dir(origin, predict):
    os.makedirs(origin, exist_ok=True)
    os.makedirs(predict, exist_ok=True)


def load_config():
    current_dir = os.path.dirname(os.path.abspath(__file__))
    if os.path.exists(os.path.join(current_dir, 'flask.yml')):
        with open(os.path.join(current_dir, 'flask.yml'), 'r', encoding='utf-8') as file:
            config = yaml.safe_load(file)
            if config['flask']['profiles']['active'] == 'test':
                with open(os.path.join(current_dir, 'flask-test.yml'), 'r', encoding='utf-8') as f:
                    config = yaml.safe_load(f)
            elif config['flask']['profiles']['active'] == 'dev':
                with open(os.path.join(current_dir, 'flask-dev.yml'), 'r', encoding='utf-8') as f:
                    config = yaml.safe_load(f)
    else:
        with open(os.path.join(current_dir, 'flask.yaml'), 'r', encoding='utf-8') as file:
            config = yaml.safe_load(file)
    new_dir(config['path']['origin_path'],config['path']['predict_path'])
    return config


if __name__ == '__main__':
    # app.run()
    print(load_config())
